package com.pig4cloud.pig.village.fund.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.village.api.entity.Fund;
import com.pig4cloud.pig.village.fund.service.IFundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author limbray.li
 * @date 2021/6/19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/fund")
@Api(value = "fund", tags = "基金管理模块")
public class FundController {
	@Resource
	private IFundService fundService;

	@GetMapping("/listAllFund")
	@ApiOperation(value = "所有基金")
	public R<List<Fund>> listAllFund() {
		return R.ok(fundService.list());
	}

	@GetMapping("/list")
	public R<IPage<Fund>> list(Integer pageNum, Integer pageSize) {
		return R.ok(fundService.page(new Page(pageNum,pageSize)));
	}

	@GetMapping("/get")
	public R<Fund> get(Long id) {
		return R.ok(fundService.getById(id));
	}

	@PutMapping("/deleteById")
	public R delete(Long id) {
		return R.ok(fundService.removeById(id));
	}

	@PostMapping("/add")
	public R add(@RequestBody Fund fund) {
		return R.ok(fundService.save(fund));
	}
}
